window.addEventListener("load", function () {
	// 找dom元素
	var backTopButton = this.document.querySelector("div.side-toolbar a:last-of-type");
	// 监听window的scroll
	this.window.onscroll = throttle(function () {
		console.log("scroll...");

		if (window.scrollY >= window.screen.height) {
			backTopButton.style.display = "block";
		} else {
			backTopButton.style.display = "none";
		}
	});
	// 给按钮添加点击事件, 点击返回顶部
	backTopButton.onclick = function () {
		document.documentElement.scrollTop = 0;
	};

	// 事件稀释
	function throttle(fn) {
		var lastEventTimestamp = null;
		return function () {
			var now = Date.now();
			if (!lastEventTimestamp || now - lastEventTimestamp >= 200) {
				lastEventTimestamp = now;
				fn();
			}
		};
	}
});
